
app:registClass("PvpController", "app.pvp.controllers.PvpController")
app:registClass("PvpChampionController", "app.pvp.controllers.PvpChampionController")
app:registClass("PvpChallengeController", "app.pvp.controllers.PvpChallengeController")
app:registClass("PvpEliteController", "app.pvp.controllers.PvpEliteController")


local PvpModel = import(".models.PvpModel")

app:registInst(PvpModel.new())

app:registInst(app:getClass("PvpController").new({type="systemUI"}))
app:registInst(app:getClass("PvpChampionController").new({type="systemUI"}))
app:registInst(app:getClass("PvpChallengeController").new({type="systemUI"}))
app:registInst(app:getClass("PvpEliteController").new({type="systemUI"}))


-- pvp 开始loading
app.session:on("pb_pvploading.S2C_PVPLoadingOpen", function(msg)
	app:sendMsg("PvpModel", "S2C_PVPLoadingOpen", msg)
end)

-- pvp loading更新
app.session:on("pb_pvploading.S2C_PVPLoadingUpdate", function(msg)
	app:sendMsg("PvpModel", "S2C_PVPLoadingUpdate", msg)
end)

-- pvp loading结束
app.session:on("pb_pvploading.S2C_PVPLoadingClose", function(msg)
	app:sendMsg("PvpModel", "S2C_PVPLoadingClose", msg)
end)

-- pvp 比赛结果
app.session:on("tournament.S2C_TournamentMatchResult", function(msg)
	app:sendMsg("PvpModel", "S2C_TournamentMatchResult", msg)
end)

-- pvp 信息更新
app.session:on("tournament.S2C_TournamentInfo", function(msg)
	app:sendMsg("PvpModel", "S2C_TournamentInfo", msg)
end)

-- kof 结果
app.session:on("pb_kingofduel.S2C_KingOfDuelResult", function(msg)
	app:sendMsg("PvpController", "S2C_KingOfDuelResult", msg)
end)

-- 重连／登陆后匹配消息同步
app.session:on("pb_map.S2C_CrossBattleInfo", function(msg)
	app:sendMsg("PvpModel", "S2C_CrossBattleInfo", msg)
end)

-- 竞技场 匹配成功
app.session:on("pb_arena.S2C_ArenaMatch", function(msg)
	print("S2C_ArenaMatch")
	app:sendMsg("PvpModel", "onPvpMatchStart", msg)
end)

-- 竞技场 匹配取消
app.session:on("pb_arena.S2C_ArenaCancel", function(msg)
	print("S2C_ArenaCancel")
	app:sendMsg("PvpModel", "onPvpMatchFail", msg)
end)

-- 竞技场 匹配失败
app.session:on("pb_arena.S2C_ArenaError", function(msg)
	print("S2C_ArenaError")
	app:sendMsg("PvpModel", "onPvpMatchFail", msg)
end)

-- 星空谜棋 匹配成功
app.session:on("pb_starchess.S2C_StarChessMatch", function(msg)
	print("S2C_StarChessMatch")
	app:sendMsg("PvpModel", "onPvpMatchStart", msg)
end)

-- 星空谜棋 匹配取消
app.session:on("pb_starchess.S2C_StarChessCancel", function(msg)
	print("S2C_StarChessCancel")
	app:sendMsg("PvpModel", "onPvpMatchFail", msg)
end)

-- 拳皇1v1 匹配成功
app.session:on("pb_kingofduel.S2C_KingOfDuelMatch", function(msg)
	print("S2C_KingOfDuelMatch")
	app:sendMsg("PvpModel", "onPvpMatchStart", msg)
end)

-- 拳皇1v1 匹配取消
app.session:on("pb_kingofduel.S2C_KingOfDuelCancel", function(msg)
	print("S2C_KingOfDuelCancel")
	app:sendMsg("PvpModel", "onPvpMatchFail", msg)
end)

-- 大乱斗 匹配成功
app.session:on("pb_melee.S2C_MeleeMatch", function(msg)
	print("S2C_MeleeMatch")
	app:sendMsg("PvpModel", "onPvpMatchStart", msg)
end)

-- 大乱斗 匹配取消
app.session:on("pb_melee.S2C_MeleeCancel", function(msg)
	print("S2C_MeleeCancel")
	app:sendMsg("PvpModel", "onPvpMatchFail", msg)
end)

-- 大乱斗 匹配失败
app.session:on("pb_melee.S2C_MeleeError", function(msg)
	print("S2C_MeleeError")
	app:sendMsg("PvpModel", "onPvpMatchFail", msg)
end)

-- 奇迹歌剧院 匹配成功
app.session:on("pb_theatre.S2C_TheatreMatch", function(msg)
	print("S2C_TheatreMatch")
	app:sendMsg("PvpModel", "onPvpMatchStart", msg)
end)

-- 奇迹歌剧院 匹配取消
app.session:on("pb_theatre.S2C_TheatreCancel", function(msg)
	print("S2C_TheatreCancel")
	app:sendMsg("PvpModel", "onPvpMatchFail", msg)
end)


-- 冠军赛 报名返回
app.session:on("pb_throne.S2C_RegisterThrone", function(msg)
	print("S2C_RegisterThrone")
	app:sendMsg("PvpModel", "onChampionRegister", msg)
end)

-- 冠军赛 服务器下发报名的队伍信息
app.session:on("pb_throne.S2C_ThroneTeamInfo", function(msg)
	print("S2C_ThroneTeamInfo")
	app:sendMsg("PvpModel", "onChampionTeamInfo", msg)
end)

-- 冠军赛 胜负及排名信息
app.session:on("pb_throne.S2C_ThroneRankInfo", function(msg)
	print("S2C_ThroneRankInfo")
	app:sendMsg("PvpModel", "onChampionRankInfo", msg)
end)

-- 冠军赛 决赛对战表
app.session:on("pb_throne.S2C_ThroneKnockOutInfo", function(msg)
	print("S2C_ThroneKnockOutInfo")
	app:sendMsg("PvpModel", "onChampionFinalTeamInfo", msg)
end) 

-- 冠军赛 比赛结果
app.session:on("pb_throne.S2C_ThroneBattleResult", function(msg)
	print("S2C_ThroneBattleResult")
	app:sendMsg("PvpModel", "onChampionBatttleResult", msg)
end)

-- 冠军赛 请求某天的16强队伍信息
app.session:on("pb_throne.S2C_ThroneKnockOutTeams", function(msg)
	print("S2C_ThroneKnockOutTeams")
	app:sendMsg("PvpModel", "onThroneKnockOutTeams", msg)
end)

-- 冠军赛，服务器下发当前状态的通知
app.session:on("pb_throne.S2C_ThroneNotifyStatus", function(msg)
	print("S2C_ThroneNotifyStatus")
	app:sendMsg("PvpModel", "onNotifyChampionStatus", msg)
end)

-- 冠军赛，匹配成功时，服务器下发通知
app.session:on("pb_throne.S2C_ThroneTeamNotify", function(msg)
	print("S2C_ThroneTeamNotify")
	app:sendMsg("PvpModel", "onNotifyChampionTeamMactchSuccess", msg)
end)

-- 挑战赛 拉取挑战赛信息
app.session:on("pb_challenge.S2C_GetChallengeInfo", function(msg)
	print("S2C_GetChallengeInfo")
	app:sendMsg("PvpModel", "onGetChallengeInfo", msg)
end)

-- 挑战赛 请求匹配
app.session:on("pb_challenge.S2C_ChallengeMatch", function(msg)
	print("S2C_ChallengeMatch")
	app:sendMsg("PvpModel", "onChallengeMatch", msg)
end)

-- 挑战赛 取消匹配
app.session:on("pb_challenge.S2C_ChallengeCancel", function(msg)
	print("S2C_ChallengeCancel")
	app:sendMsg("PvpModel", "onChallengeCancelMatch", msg)
end)

-- 挑战赛 匹配成功通知客服端准备
app.session:on("pb_challenge.S2C_PrepareNotify", function(msg)
	print("S2C_PrepareNotify")
	dump(msg)
	app:sendMsg("PvpModel", "onChallengePrepareNotify", msg)
end)

-- 挑战赛 请求准备或取消准备
app.session:on("pb_challenge.S2C_ChallengePrepare", function(msg)
	print("S2C_ChallengePrepare")
	app:sendMsg("PvpModel", "onChallengeClientPrepare", msg)
end)

-- 挑战赛 服务器通知惩罚信息
app.session:on("pb_challenge.S2C_PunishNotify", function(msg)
	print("S2C_PunishNotify")
	app:sendMsg("PvpModel", "onChallengePunishNotify", msg)
end)

-- 挑战赛 服务器通知当前开启状态（登录游戏，开始挑战赛， 结束挑战赛）
app.session:on("pb_challenge.S2C_ChallengeOpenInfo", function(msg)
	print("S2C_ChallengeOpenInfo")
	app:sendMsg("PvpModel", "onChallengeOpenInfo", msg)
end)

-- 挑战赛 服务器通知结算结果
app.session:on("pb_challenge.S2C_ChallengeMatchResult", function(msg)
	print("S2C_ChallengeMatchResult")
	app:sendMsg("PvpModel", "onChallengeMatchResult", msg)
end)

-- 挑战赛 服务器返回检查匹配条件
app.session:on("pb_challenge.S2C_ChallengeCheckMatchCondition", function(msg)
	print("S2C_ChallengeCheckMatchCondition")
	app:sendMsg("PvpModel", "onChallengeCheckMatchCondition", msg)
end)

-- 挑战赛 服务器返回再来一局
app.session:on("pb_challenge.S2C_ChallengeOneMoreGame", function(msg)
	print("S2C_ChallengeOneMoreGame")
	app:sendMsg("PvpModel", "onChallengeOneMoreGame", msg)
end)

-- 决斗赛信息刷新
app.session:on("pb_duel.S2C_GetDuelInfo", function(msg)
	print("S2C_GetDuelInfo")
	app:sendMsg("PvpModel", "onDuelInfo", msg)
end)


-- 决斗赛战斗结束信息
app.session:on("pb_duel.S2C_DuelBattleResult", function(msg)
	print("S2C_DuelBattleResult")
	app:sendMsg("PvpController", "openDuelFightEndWin", msg)
end)

-- 决斗赛排名下降信息
app.session:on("pb_duel.S2C_DuelRankChangeNotify", function(msg)
	print("S2C_DuelRankChangeNotify")
	if msg and msg.rankChange then
		app:sendMsg("PvpController", "showDuelRankChangeTips", msg.rankChange)
	end
end)


-- 跨服 工会战 比赛结果
app.session:on("pb_world.S2C_WorldGuildWarBattleEnd", function(msg)
	print(os.date("%y/%m/%d, %H:%M:%S", app.session:getServerTime()))
	print("S2C_WorldGuildWarBattleEnd")
	-- app:sendMsg("PvpModel", "S2C_WorldGuildWarBattleEnd", msg)
end)


------------------------ 跨服精英赛 Start -----------------------------
-- 服务器通知开放信息
app.session:on("pb_combatcross.S2C_CombatCrossOpenInfo", function(msg)
    -- dump(msg, "S2C_CombatCrossOpenInfo")
    UD.csEliteMatch:onCombatCrossOpenInfo(msg)
end)

-- 战斗结果
app.session:on("pb_combatcross.S2C_CrossCombatBattleResult", function(msg)
    -- dump(msg, "S2C_CrossCombatBattleResult")
    UD.csEliteMatch:onCrossCombatBattleResult(msg)
end)

-- 开始匹配
app.session:on("pb_combatcross.S2C_CombatCrossMatch", function(msg)
   -- dump(msg, "S2C_CombatCrossMatch") 
   UD.csEliteMatch:onCombatCrossMatch(msg)
end)

-- 取消匹配
app.session:on("pb_combatcross.S2C_CombatCrossCancel", function(msg)
    -- dump(msg, "S2C_CombatCrossCancel")
    UD.csEliteMatch:onCombatCrossCancel(msg) 
end)

-- 检查匹配条件
app.session:on("pb_combatcross.S2C_CombatCrossCheckMatchCondition", function(msg)
    -- dump(msg, "S2C_CombatCrossCheckMatchCondition")
    UD.csEliteMatch:onCombatCrossCheckMatchCondition(msg)
end)

-- 准备信息——游戏服通知客户端准备
app.session:on("pb_combatcross.S2C_CrossCombatPrepareNotify", function(msg)
    -- dump(msg, "S2C_CrossCombatPrepareNotify")
    UD.csEliteMatch:onCrossCombatPrepareNotify(msg)
end)

-- 惩罚信息——游戏服通知客户端惩罚
app.session:on("pb_combatcross.S2C_CrossCombatPunishNotify", function(msg)
    -- dump(msg, "S2C_CrossCombatPunishNotify")
    UD.csEliteMatch:onCrossCombatPunishNotify(msg)
end)

-- 精英决斗赛查询阵容信息
app.session:on("pb_combatcross.S2C_QueryNowTeamInfo", function(msg)
    -- dump(msg, "S2C_QueryNowTeamInfo")
    UD.csEliteMatch:onQueryNowTeamInfo(msg)
end)
------------------------ 跨服精英赛 End -----------------------------